﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GC2.Bussines;
using GC2.Bussines.BMAdmin;
using GC2.Entities.Admin;
using GC2.Entities.Seguridad;
using GC2.ExceptionHandler;

public partial class Informes_IngresosAdmin : GenericPage
{
    #region Propiedades
    Usuarios usuario = new Usuarios();
    List<Conceptos> listaConceptos = new List<Conceptos>();    
    #endregion

    #region Controles
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            SetearCultura();
            SetearConexion();
            if (!IsPostBack)
            {
                usuario = (Usuarios)Session["UsuarioActual"];
                BMConceptos bmConceptos = new BMConceptos(Connection);
                Conceptos concepto = new Conceptos();
                concepto.Id_Tipo = 2; // 1 Ingresos - 2 Ingresos
                listaConceptos = bmConceptos.BMConceptosSearch(concepto);
                Session["listaConceptos"] = listaConceptos;
                CargarGrilla();
            }
        }
        catch (Exception ex) { ErrorUI(ex); }
    }

    protected void gvIngresos_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvIngresos.PageIndex = e.NewPageIndex;
        CargarGrilla();
    }


    protected void gvIngresos_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            listaConceptos = (List<Conceptos>)Session["listaConceptos"];
            BMConceptos bmConceptos = new BMConceptos(Connection);
            Conceptos concepto = new Conceptos();
            concepto.Id_Concepto = (int)gvIngresos.SelectedDataKey.Value;
            foreach (Conceptos item in listaConceptos)
            {
                if (item.Id_Concepto == concepto.Id_Concepto)
                {
                    concepto.Concepto = item.Concepto;
                    break;
                }
            }

            Session["Concepto"] = concepto;
            Response.Redirect("porIngreso.aspx", false);
        }
        catch (Exception ex) { ErrorUI(ex); }
    }

    protected void btnCancelar_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Seguridad/Default.aspx", false);
    }

    #endregion

    #region Métodos

    private void CargarGrilla()
    {
        try
        {
            listaConceptos = (List<Conceptos>)Session["listaConceptos"];
            gvIngresos.DataSource = listaConceptos;
            gvIngresos.DataBind();
        }
        catch (Exception ex) { ErrorUI(ex); }
    }

    #endregion
}